package cn.ml.gaoJi.jiHe.collections.listToMap;

import cn.ml.entity.Student;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectionSortDemo {
    public static void main(String[] args) {

        List<Student> studentList = Student.getStudentList();
        Student s1 = new Student(2,"李小明","男",18,1.76, LocalDate.of(2001,3,23), new BigDecimal(1111));
        Student s2 = new Student(4,"张小丽","女",18,1.61,LocalDate.of(2001,6,3), new BigDecimal(1111));
        Student s3 = new Student(3,"王大朋","男",19,1.82, LocalDate.of(2000,3,11), new BigDecimal(1111));
        Student s4 = new Student(1,"陈小跑","女",17,1.67,LocalDate.of(2002,10,18), new BigDecimal(1111));
        List students = new ArrayList();
        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);
        System.out.println("*****************排序【前】列表****************************");
        students.stream().forEach(System.out::println);
        // 自定义按年龄排序
        Collections.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge().compareTo(o2.getAge());
            }
        });
        System.out.println("*****************排序【后】列表****************************");

        students.stream().forEach(System.out::println);
    }
}
